Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useformstate): properly assert that field types inferred from yup schema are defined #60

Merged
merged 1 commit into from
Apr 28, 2021

Conversation

mturley
Copy link
Collaborator

@mturley mturley commented Apr 27, 2021

Also adds a "Complex field types and validations" example to the docs.

After #59, I realized that a schema e.g. yup.mixed<T>() would cause TypeScript to infer the field type as T | undefined. This is especially annoying for things like arrays where it would expect every element to be possibly undefined. To prevent ripple effects on all form code that previously assumed field values are always defined unless specified otherwise, I changed the type annotations on useFormField such that T will always be inferred as a defined value.

The side effect of this is that it is now invalid to allow undefined field values in useFormState, but that is an antipattern anyway, because null should be used for intentionally blank fields.

Required for an upcoming forklift-ui PR.

@mturley mturley requested a review from a team April 27, 2021 23:54
@codecov
Copy link

codecov bot commented Apr 27, 2021

Codecov Report

Merging #60 (4835620) into main (a1e3601) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##              main       #60   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           19        19           
  Branches         5         5           
=========================================
  Hits            19        19           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a1e3601...4835620. Read the comment docs.

@konveyor-preview-bot
Copy link

🚀 Deployed Storybook Preview: http://konveyor-lib-ui-pr-60-preview.surge.sh

… schema are defined

Also adds a "Complex field types and validations" example to the docs
@mturley mturley requested review from gildub and ibolton336 April 28, 2021 15:23
Copy link
Collaborator

@gildub gildub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gildub gildub merged commit 26a34c0 into migtools:main Apr 28, 2021
@mturley mturley deleted the yup-schema-fixes branch April 28, 2021 17:08
@konveyor-release-bot
Copy link

🎉 This PR is included in version 4.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants